package com.luck.dto;

import com.luck.config.dto.Order;
import com.luck.config.dto.OrderQuery;
import com.luck.config.dto.OrderingDTO;
import com.luck.config.dto.OrderingOk;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

@Slf4j
@RestController
@RequestMapping("/api/order")
public class OrderController {
    @PostMapping
    public OrderingOk ordering(@RequestBody OrderingDTO dto){
        log.debug("{}",dto);
        return new OrderingOk().setId(1L).setNeedPay(new BigDecimal(100));
    }
    @GetMapping
    public List<Order> select(OrderQuery query){
        log.debug("{}",query);
        List<Order> orders = new ArrayList<Order>();
        if(query.getUserName().equals("张三")){
            Order order1 = new Order().setId(1L).setNeedPay(new BigDecimal(100)).setUserName("张三");
            Order order2 = new Order().setId(2L).setNeedPay(new BigDecimal(100)).setUserName("张三");
            orders.add(order1);
            orders.add(order2);
        }
        return orders;
    }
}
